package com.yingsheng.bi.hks.web.controller;

import com.yingsheng.bi.hks.basic.enums.EnumConst;
import com.yingsheng.bi.hks.dto.contract.*;
import com.yingsheng.bi.hks.feign.client.ContractFeignClient;
import com.yingsheng.bi.hks.service.contract.ContracMgmtService;
import com.yingsheng.bi.hks.template.annotation.Template;
import com.yingsheng.bi.hks.template.utils.JacksonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.UriUtils;

import java.nio.charset.StandardCharsets;

/**
 * 合同管理
 *
 * @author 83686
 */
@RestController
public class ContractCtrl implements ContractFeignClient {

    @Autowired
    private ContracMgmtService contracMgmtService;

    @Template(name = "accessQueryTemplate")
    @Override
    public ContractTemplateQryRes templateQry(@Validated ContractTemplateQryReq req) {
        ContractTemplateQryRes res = new ContractTemplateQryRes();
        res.setType(EnumConst.ContractType.CONTRACT_TYPE_0);
        res.setName("欣佳源家政管理制合同-客户");
        return res;
    }

    @Template(name = "publicTransTemplate")
    @Override
    public ContractOneSendRes templateOneSend(@Validated ContractOneSendReq req) {
        return contracMgmtService.templateOneSend(req);
    }

    @Template(name = "accessTransTemplate")
    @Override
    public CreateContractTokenRes createContractToken(@Validated CreateContractTokenReq req) {
        return contracMgmtService.createContractToken(req);
    }

    @Template(name = "accessTransTemplate")
    @Override
    public ContractDownLoadRes contractDownLoad(@Validated ContractDownLoadReq req) {
        return contracMgmtService.contractDownLoad(req);
    }

    @Template(name = "accessTransTemplate")
    @Override
    public ContractsQryRes contractsQry(@Validated ContractsQryReq req) {
        return contracMgmtService.contractsQry(req);
    }

//    @Template(name = "qiYueSuoTemplate")
    @Override
    public String QYSnotice(@RequestParam("content") String contentEncode) {
        String contentDecode = UriUtils.decode(contentEncode, StandardCharsets.UTF_8);
        QYSnoticeReq req = JacksonUtils.json2Obj(contentDecode, QYSnoticeReq.class);
        return contracMgmtService.QYSnotice(req);
    }

    @Template(name = "publicQueryTemplate")
    @Override
    public BrowseRes browse(@Validated BrowseReq req) {
        return contracMgmtService.browse(req);
    }


}
